//
//  DCImageAndTextFieldView.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/1.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCImageAndTextFieldView.h"
@interface DCImageAndTextFieldView ()


@end
@implementation DCImageAndTextFieldView
+(instancetype)creatViewWithFrame:(CGRect)frame image:(UIImage *)image imageShape:(DCImageShape)imageShape imageHeight:(CGFloat)imgH placeholder:(NSString *)placeholder isEdit:(BOOL)isEdit {
    return [[self alloc]initWithFrame:frame image:image imageShape:imageShape imageHeight:imgH placeholder:placeholder isEdit:isEdit];
}
-(instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image imageShape:(DCImageShape)imageShape imageHeight:(CGFloat)imgH placeholder:(NSString *)placeholder isEdit:(BOOL)isEdit{
    
    self = [super init];
    if (!self) {
        return nil;
    }
    self.frame = frame;
    
    UIView *img = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60*WIDTHSCALE6, frame.size.height)];
//    img.backgroundColor = RandomColor;
    [self addSubview:img];
    
    self.imageView = [[UIImageView alloc]initWithImage:image];
    if (imageShape == ImageIsSquare) {
        self.imageView.size = CGSizeMake(imgH, imgH);
    }else{
        self.imageView.size = CGSizeMake(imgH+10, imgH);
    }
    self.imageView.x = (img.width - self.imageView.width)/2;
    self.imageView.y = (img.height - imgH)/2;
    [img addSubview:self.imageView];
    
    self.textField = [[UITextField alloc]init];
    self.textField.frame = CGRectMake(img.right+4, 0, frame.size.width - img.width - 4, frame.size.height-1);
    self.textField.enabled = isEdit;
    self.textField.placeholder = placeholder;
    [self addSubview:self.textField];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(self.textField.x, self.textField.bottom, self.textField.width, 1)];
    line.backgroundColor = BackgroundColor;
    [self addSubview:line];
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
